package com.project.server.operate;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.common.utils.poi.ExcelUtil;
import com.project.server.domain.operate.TOperateContract;
import com.project.server.service.operate.ITOperateContractService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * 运营管理合同Controller
 *
 * @author project
 * @date 2021-06-29
 */
@RestController
@RequestMapping("/server/contract")
public class TOperateContractController extends BaseController {

    @Resource
    private ITOperateContractService tOperateContractService;

    /**
     * 查询运营管理合同列表
     */
    @PreAuthorize("@ss.hasPermi('server:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(TOperateContract tOperateContract) {
        startPage();
        List<TOperateContract> list = tOperateContractService.selectTOperateContractList(tOperateContract);
        return getDataTable(list);
    }


    /**
     * 导出运营管理合同列表
     */
    @PreAuthorize("@ss.hasPermi('server:contract:export')")
    @Log(title = "运营管理合同", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TOperateContract tOperateContract) {
        List<TOperateContract> list = tOperateContractService.selectTOperateContractList(tOperateContract);
        ExcelUtil<TOperateContract> util = new ExcelUtil<TOperateContract>(TOperateContract.class);
        return util.exportExcel(list, "合同管理列表");
    }

    /**
     * 获取运营管理合同详细信息
     */
    @PreAuthorize("@ss.hasPermi('server:contract:query')")
    @GetMapping(value = "/{contractId}")
    public AjaxResult getInfo(@PathVariable("contractId") Long contractId) {
        return AjaxResult.success(tOperateContractService.selectTOperateContractById(contractId));
    }

    /**
     * 新增运营管理合同
     */
    @PreAuthorize("@ss.hasPermi('server:contract:add')")
    @Log(title = "运营管理合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestParam(value = "file") MultipartFile[] file, TOperateContract tOperateContract) {
        return toAjax(tOperateContractService.insertTOperateContract(file,tOperateContract));
    }

    /**
     * 修改运营管理合同
     */
    @PreAuthorize("@ss.hasPermi('server:contract:edit')")
    @Log(title = "运营管理合同", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestParam(value = "file") MultipartFile[] file, TOperateContract tOperateContract) {
        return toAjax(tOperateContractService.updateTOperateContract(file,tOperateContract));
    }

    /**
     * 删除运营管理合同
     */
    @PreAuthorize("@ss.hasPermi('server:contract:remove')")
    @Log(title = "运营管理合同", businessType = BusinessType.DELETE)
    @DeleteMapping("/{contractIds}")
    public AjaxResult remove(@PathVariable Long[] contractIds) {
        return toAjax(tOperateContractService.deleteTOperateContractByIds(contractIds));
    }
}
